Socket
Socket
Sign inDemoInstall

timezone-support

Package Overview
Dependencies
1
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    timezone-support

Lightweight time zone support for your applications or other date libraries.


Version published
Weekly downloads
144K
decreased by-0.47%
Maintainers
1
Install size
20.0 MB
Created
Weekly downloads
 

Package description

What is timezone-support?

The timezone-support npm package provides utilities for working with time zones, including converting dates between time zones, parsing and formatting dates, and handling daylight saving time transitions.

What are timezone-support's main functionalities?

Convert Date Between Time Zones

This feature allows you to convert a date from one time zone to another. The code sample demonstrates converting a UTC date to 'America/New_York' time zone.

const { convertTimeToTimeZone } = require('timezone-support');
const { parseFromTimeZone, formatToTimeZone } = require('date-fns-timezone');

const date = new Date('2023-10-01T12:00:00Z');
const timeZone = 'America/New_York';
const convertedDate = convertTimeToTimeZone(date, { timeZone });
console.log(convertedDate);

Parse Date from Time Zone

This feature allows you to parse a date string in a specific time zone. The code sample demonstrates parsing a date string in the 'America/New_York' time zone.

const { parseFromTimeZone } = require('timezone-support');

const dateStr = '2023-10-01 12:00:00';
const timeZone = 'America/New_York';
const parsedDate = parseFromTimeZone(dateStr, { timeZone });
console.log(parsedDate);

Format Date to Time Zone

This feature allows you to format a date to a specific time zone. The code sample demonstrates formatting a UTC date to 'America/New_York' time zone with a specific format.

const { formatToTimeZone } = require('timezone-support');

const date = new Date('2023-10-01T12:00:00Z');
const timeZone = 'America/New_York';
const format = 'YYYY-MM-DD HH:mm:ss [GMT]Z (z)';
const formattedDate = formatToTimeZone(date, { timeZone, format });
console.log(formattedDate);

Other packages similar to timezone-support

Readme

Source

Time Zone Support

NPM version Build Status Coverage Status Codacy Badge Dependency Status devDependency Status JavaScript Style Guide

NPM Downloads

Lightweight time zone listing and date converting. Intended for adding time zone support to high-level date libraries, but also for direct application usage.

  • Tiny code base - 4.6 KB minified, 1.7 KB gzipped. Do not pack unnecessary weight in your application.
  • Packed time zone data - 923 KB minified, 33.3 KB gzipped. Single time zones are unpacked on demand.
  • Smaller bundles with limited data - 1900-2050 (204 kB minified, 25.2 kB gzipped), 1970-2038 (204 kB minified, 25.2 kB gzipped) and 2012-2022 (31.2 KB minified, 8.2 kB gzipped).
  • Generated from the official time zone database version 2018g. Canonical time zone names, aliases, UTC offsets, and daylight-saving time changes.
  • Minimal interface for time zone lookup and conversions. Parsing, formatting and manipulating dates is usually the task for a higher-level date library.

Table of Contents

Synopsis

const {
  listTimeZones, findTimeZone, getZonedTime, getUnixTime
} = require('timezone-support')

// List canonical time zone names: [ 'Africa/Abidjan', ... ]
const timeZones = listTimeZones()

// Find a particular time zone: { name: 'Europe/Berlin', ... }
const berlin = findTimeZone('Europe/Berlin')

// Convert a date to a specific time zone: { year, month, day, dayOfWeek,
// hours, minutes, seconds, milliseconds, epoch, zone: { abbreviation, offset } }
const nativeDate = new Date()
const berlinTime = getZonedTime(nativeDate, berlin)

// Convert a time from a specific time zone: native Date object
const berlinTime = { year: 2018, month: 9, day: 2, hours: 10, minutes: 0 }
const nativeDate = new Date(getUnixTime(berlinTime, berlin))

Installation and Getting Started

This module can be installed in your project using NPM or [Yarn]. Make sure, that you use Node.js version 6 or newer.

$ npm i timezone-support --save
$ yarn add timezone-support

Functions are exposed as named exports from the package modules, for example:

const { findTimeZone, getZonedTime } = require('timezone-support')

You can read more about the module loading in other environments, like with ES6 or in web browsers. Usage scenarios demonstrate applications of this library in typical real-world scenarios. Design concepts explain the approach to time zone handling taken by tni library and types of values used ion the interface. Generating custom time zone data will allow you to save the overall package size by limiting the supported year span. Finally, the API reference lists all functions with a description of their functionality.

Library Integrations

  • Day.js - timeZone plugin supplies parsing from and formatting to an arbitrary time zone
  • date-fns - date-fns-timezone provides functions for parsing from and formatting to an arbitrary time zone and time zone conversions for the native Date object.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • 2018-11-17 v1.8.0 Include time zone data for years 1970-2038.
  • 2018-11-17 v1.7.0 Include full time zone data separately loadable.
  • 2018-11-06 v1.6.0 Upgrade the time zone database to the version 2018g.
  • 2018-10-08 v1.5.5 Fix compatibility with IE. Thanks, Andrii!
  • 2018-10-06 v1.5.0 Add TypeScript export declarations.
  • 2018-09-30 v1.4.0 Add limited data for just the current decade - years 2012-2022.
  • 2018-09-18 v1.3.0 Maintain the property dayOfWeek in the time object.
  • 2018-09-16 v1.2.0 Add a new getUTCOffset method for more lightweight integrations.
  • 2018-09-03 v1.1.0 Set the property epoch to the time object.
  • 2018-09-02 v1.0.0 Initial release

License

Copyright (c) 2018 Ferdinand Prantl

Licensed under the MIT license.

Keywords

FAQs

Last updated on 27 Nov 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc